﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using com.dz.ht.components;
using com.dz.ht.common;

namespace com.dz.ht.services
{
    public partial class DZService : ServiceBase
    {
        Thread m_thd_3_1 = null;
        Thread m_thd_3_2 = null;
        Thread m_thd_3_3 = null;
        Thread m_thd_4_1 = null;
        Thread m_thd_4_2 = null;
        Thread m_thd_4_3 = null;

        public DZService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            /*
            NetBookManger t_net_mgr = new NetBookManger();
            try
            {
                if (AppConfig.SiteNameList.IndexOf("site_3") > -1)
                {
                    t_net_mgr.InDB = true;
                    t_net_mgr.SiteName = "site_3";

                    m_thd_3_1 = new Thread(t_net_mgr.StartBookFromWeb);
                    m_thd_3_1.Name = "m_thd_3_1";
                    m_thd_3_1.Start();

                    LogHelper.Info("m_thd_3_1 启动...");

                    if (AppConfig.EnableDb)
                    {

                        m_thd_3_2 = new Thread(t_net_mgr.StartBookFromDB_ASC);
                        m_thd_3_2.Name = "m_thd_3_2";
                        m_thd_3_2.Start();

                        LogHelper.Info("m_thd_3_2 启动...");

                        m_thd_3_3 = new Thread(t_net_mgr.StartBookFromDB_DESC);
                        m_thd_3_3.Name = "m_thd_3_3";
                        m_thd_3_3.Start();

                        LogHelper.Info("m_thd_3_3 启动...");
                    }
                }

                if (AppConfig.SiteNameList.IndexOf("site_4") > -1)
                {
                    t_net_mgr.InDB = true;
                    t_net_mgr.SiteName = "site_4";

                    m_thd_4_1 = new Thread(t_net_mgr.StartBookFromWeb);
                    m_thd_4_1.Name = "m_thd_4_1";
                    m_thd_4_1.Start();

                    LogHelper.Info("m_thd_4_1 启动...");

                    if (AppConfig.EnableDb)
                    {
                        m_thd_4_2 = new Thread(t_net_mgr.StartBookFromDB_ASC);
                        m_thd_4_2.Name = "m_thd_4_2";
                        m_thd_4_2.Start();

                        LogHelper.Info("m_thd_4_2 启动...");

                        m_thd_4_3 = new Thread(t_net_mgr.StartBookFromDB_DESC);
                        m_thd_4_3.Name = "m_thd_4_3";
                        m_thd_4_3.Start();

                        LogHelper.Info("m_thd_4_3 启动...");
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("启动线程失败" + ex.ToString());
            }*/
        }

        protected override void OnStop()
        {
            try
            {
                if (m_thd_3_1 != null)
                {
                    m_thd_3_1.Abort();
                    LogHelper.Info("m_thd_3_1 停止...");
                }

                if (m_thd_3_2 != null)
                {
                    m_thd_3_2.Abort();
                    LogHelper.Info("m_thd_3_2 停止...");
                }

                if (m_thd_3_3 != null)
                {
                    m_thd_3_3.Abort();
                    LogHelper.Info("m_thd_3_3 停止...");
                }

                if (m_thd_4_1 != null)
                {
                    m_thd_4_1.Abort();
                    LogHelper.Info("m_thd_4_1 停止...");
                }

                if (m_thd_4_2 != null)
                {
                    m_thd_4_2.Abort();
                    LogHelper.Info("m_thd_4_2 停止...");
                }

                if (m_thd_4_3 != null)
                {
                    m_thd_4_3.Abort();
                    LogHelper.Info("m_thd_4_3 停止...");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("关闭线程失败" + ex.ToString());
            }
        }
    }
}
